//@module

exports.Destructuring = {

	run(){
		
		//let obj = { first: 'Jane', last: 'Doe' };
		
		//let { first: f, last: l } = obj;
		
		//trace(f + " " +l);
		
		//let {length : len} = 'abc'; // len = 3
		//let {toString: s} = 123; // s = Number.prototype.toString
		
		//trace(len+"\n");
		//trace(s);

		//let { prop: x } = undefined; // 
		//let { prop: y } = null; // 
		
		//let obj = { a: [{ foo: 123, bar: 'abc' }, {}], b: true };
		//let { a: [{foo: f}] } = obj; 
		
		//let { x: x } = { x: 7, y: 3 };
		
		//trace(f);
		//trace(x);
		//let x;
		//let { x, y } = { x: 11, y: 8 };
		//trace(x + " " + y);
		
		//const FOO = 'foo';
		//let { [FOO]: f } = { foo: 123 }; // f = 123
		
		//trace(f);
		
		//let x,y,obj = { x: 7, y: 3 };
		
		//({x,y} = obj);

		
		function bar() {
			return {
				x: 4,
				y: 5,
				z: 6
			};
		}
		
		//var o = {}
		//({x:o.x,y:o.x,z:o.z} = {x:2,y:4,z:5})
		/*var o = { a:1, b:2, c:3 },
		a, b, c, p;
		p = {a} = {a,b,c} = o;
		trace( a, b, c ); // 1 2 3
		trace(p === o);*/
		
		//function log(x) { trace(x+"\n"); return 'YES' }
		
		/*let {x:a = log(4)} = {x:0};
		
		trace(a);*/
		
		//let [a=log('hello')] = [1];
		
		//trace(a)
		
		
		/*function findArray(arr,cb){
			for(let i=0;i<arr.length;i++){
				if(cb(arr[i])){
					return {ele:arr[i],index:i};
				}
			}
			return {ele:undefined,index:-1};
		}
		
		let arr = [21,3,5,6,7],cb = function(ele){return ele % 2 == 0};
		
		
		let {index} = findArray(arr,cb);
		trace(index);*/
		
		//let [x, y] = ['a', 'b']; // x = 'a'; y = 'b'
		
		//trace(x + " " + y);
		
		//let [x] = []; // x = undefined
		
		/*var o = [1,2,3],a, b, c, p;
		p = [,,c] = [a,b] = o;
		trace( a + b + c ); // 1 2 3
		trace(p === o); // true*/
		
		//var a1 = [ 1, [2, 3, 4,7,8], 5 ];
		//var [ a, [ b, c,...d], e ] = a1;
		
		//let [{ prop: x } = {}] = [{prop:4}];
		///trace(x);
		
		
		/*function foo( [ x, y ] ) {
			trace( x + " " +y );
		}
		foo( [ 1, 2 ] ); // 1 2
		foo( [ 1 ] ); // 1 undefined
		foo( [] );*/
		
		/*function f({ x = 10 } = {}, { y } = { y: 10 }) {
			trace( x + " " + y +"\n");
		}
		
		f(); // 10 10
		f( undefined, undefined ); // 10 10
		f( {}, undefined ); // 10 10
		f( {}, {} ); // 10 undefined
		f( undefined, {} ); // 10 undefined
		f( { x: 2 }, { y: 3 } ); // 2 3*/
		
		/*function move1({x=0, y=0} = {}) {
			trace(x + " " + y + "\n");
		}
		
		function move2({x, y} = { x: 0, y: 0 }) {
			trace(x + " " + y + "\n");
		}
		
		move1({x: 3, y: 8}); 
		move1({x: 3}); 
		move1({}); 
		move1(); 
		move1({z:3})
		
		trace("\n");
		
		move2({x: 3, y: 8}); 
		move2({x: 3}); 
		move2({}); 
		move2(); 
		move2({z:3})*/
		
		function f([ x=2, y=3, z ]) {
			trace(x + " " +y + " " + z + "\n");
		}
		
		//f();//# Exception: f: cannot coerce undefined to object!
		f([1]);//1 3 undefined
		f([1,2]);//1 2 undefined
		f([1,2,3]);//1 2 3
		f([1,2,3,4]);//1 2 3
	}
}
